﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using Newtonsoft.Json;

namespace MapleLeaf.Pay.Pay {

    public class HongshPayClientConfig : HongshPayConfig, INotifyPropertyChanged {

        public event PropertyChangedEventHandler PropertyChanged;


        [JsonIgnore]
        public HongshPayApi Api {
            get {
                if (!Apis.TryGetValue(DefaultApiKey, out HongshPayApi result)) {
                    result = Apis[DefaultApiKey] = new HongshPayApi();
                }
                return result;
            }
        }


        public Dictionary<string, HongshPayApi> Apis {
            get {
                if (_Apis == null) {
                    _Apis = new Dictionary<string, HongshPayApi>();
                }
                return _Apis;
            }
            set {
                _Apis = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Apis"));
            }
        }

        public int MinWindowX {
            get => _MinWindowX;
            set {
                _MinWindowX = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MinWindowX"));
            }
        }

        public int MinWindowY {
            get => _MinWindowY;
            set {
                _MinWindowY = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MinWindowY"));
            }
        }
        public int TradeDuration {
            get => _TradeDuration;
            set {
                _TradeDuration = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TradeDuration"));
            }
        }

        public int HttpTimeout {
            get => _HttpTimeout;
            set {
                _HttpTimeout = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HttpTimeout"));
            }
        }


        public int TradeResultStay {
            get => _TradeResultStay;
            set {
                _TradeResultStay = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TradeResultStay"));
            }
        }


        public bool TradeResultPlayer {
            get => _TradeResultPlayer;
            set {
                _TradeResultPlayer = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TradeResultPlayer"));
            }
        }

        public string PrinterName {
            get => _PrinterName;
            set {
                _PrinterName = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("PrinterName"));
            }
        }


        public bool HideOnLoad {
            get => _HideOnLoad;
            set {
                _HideOnLoad = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("_HideOnLoad"));
            }
        }

        public string RedirectPrinterName {
            get => _RedirectPrinterName;
            set {
                _RedirectPrinterName = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("RedirectPrinterName"));
            }
        }

        public int PrintInvert {
            get => _PrintInvert;
            set {
                _PrintInvert = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("PrintInvert"));
            }
        }

        public int TradePrintCount {
            get => _TradePrintCount;
            set {
                _TradePrintCount = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TradePrintCount"));
            }
        }


        public string TradePrintTitle {
            get => _TradePrintTitle;
            set {
                _TradePrintTitle = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TradePrintTitle"));
            }
        }


        public string TradePrintTail {
            get => _TradePrintTail;
            set {
                _TradePrintTail = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TradePrintTail"));
            }
        }

        public string HKShowHide {
            get => _HKShowHide;
            set {
                _HKShowHide = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HKShowHide"));
            }
        }

        public bool IsMinWindowShow {
            get => _IsMinWindowShow;
            set {
                _IsMinWindowShow = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsMinWindowShow"));
            }
        }


        public bool IsTradeSoundPlay {
            get => _IsTradeSoundPlay;
            set {
                _IsTradeSoundPlay = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsTradeSoundPlay"));
            }
        }
        public HongshPayClientConfig() {
            _MinWindowX = 60;
            _MinWindowY = 60;
            _TradeDuration = 100;
            _HttpTimeout = 15;
            _TradeResultStay = 3;
            _HideOnLoad = false;
            _TradePrintTail = "感谢您的惠顾！如有疑问请咨询工作工员。";
            _HKShowHide = "Pause";
        }

        static HongshPayClientConfig() {
            DefaultApiKey = "0.0.0.0";
        }


        private static readonly string DefaultApiKey;

        private Dictionary<string, HongshPayApi> _Apis;

        private int _MinWindowX;

        private int _MinWindowY;


        private int _TradeDuration;


        private int _HttpTimeout;


        private int _TradeResultStay;


        private bool _TradeResultPlayer;


        private string _PrinterName;


        private bool _HideOnLoad;


        private string _RedirectPrinterName;


        private int _PrintInvert;


        private int _TradePrintCount;


        private string _TradePrintTitle;


        private string _TradePrintTail;

        private string _HKShowHide;


        private bool _IsMinWindowShow;


        private bool _IsTradeSoundPlay;
    }
}
